// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   PostCreateController.java

package dale.web.post.controller;

import dale.web.category.domain.Category;
import dale.web.post.domain.Post;
import dale.web.post.domain.PostValidator;
import dale.web.post.service.PostService;
import dale.web.tag.domain.Tag;
import java.util.List;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;

public class PostCreateController
{

    public PostCreateController(PostService service, PostValidator validator)
    {
        this.service = service;
        this.validator = validator;
    }

    protected void initBinder(WebDataBinder binder)
    {
        binder.setValidator(validator);
    }

    public String get(Post post, Model model)
    {
        model.addAttribute(post);
        return "post/create";
    }

    public String post(Post post, BindingResult result)
    {
        if(result.hasErrors())
        {
            return "post/create";
        } else
        {
            int postNo = service.create(post);
            return (new StringBuilder("redirect:/post/detail/")).append(postNo).toString();
        }
    }

    public List getCategoryList()
    {
        List categoryList = service.categoryList(new Category());
        return categoryList;
    }

    public List getTagList()
    {
        List tagList = service.tagList(new Tag());
        return tagList;
    }

    private PostService service;
    private PostValidator validator;
}
